package com.disktalk.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.disktalk.dao.GroupUserDao;
import com.disktalk.entry.GroupUser;
@Service
public class GroupUserService {
	@Resource
	private GroupUserDao groupUserDao;
	/*
	 *添加用户组关系 
	 */
	public String addGroupUser(GroupUser groupUser) {
		try {
			if(groupUserDao.find(groupUser)){
				return "exist";
			}else{
				groupUserDao.addGroupUser(groupUser);
				return "succsse";
			}
		} catch (Exception e) {
			return "false";
		}
			
	}
	/*
	 *移除用户组关系 
	 */
	public String delGroupUser(GroupUser groupUser) {
		try {
			if(!groupUserDao.find(groupUser)){
				return "no exist";
			}else{
				groupUserDao.delGroupUser(groupUser);
				return "succsse";
			}
		} catch (Exception e) {
			return "false";
		}
			
	}
	/*
	 * 查询用户已加入的组
	 */
	public List<String> findGroupByUser(String userName) { 
		List<String> groupNames = groupUserDao.findByUserName(userName);
		return groupNames;
	}
	/*
	 * 查询用组内用户
	 */
	public List<String> findUserbyGroup(String groupName) { 
		List<String> userNames = groupUserDao.findByGroupName(groupName);
		return userNames;
	}
}
